<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
  <cpn @itemclick="btnClick"></cpn>
  <h3>我是父亲的事件，我被点击了{{frequency}}次。现在我的值是{{num}}</h3>
</div>
<template id="cpn">
  <div>
    <button @click="increment">+</button>
    {{num}}
    <button @click="decrement">-</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>
  const cpn = {
    template: '#cpn',
    data() {
      return {
        num: 0
      }
    },
    methods: {
      increment() {
        this.num++
        this.$emit('itemclick', this.num)
      },
      decrement() {
        this.num--
        this.$emit('itemclick', this.num)
      }
    }

  }

  const vm = new Vue({
    el: '#app',
    data: {
      frequency:0,
      num: 0
    },
    components: {
      cpn
    },
    methods: {
      btnClick(num) {
        console.log(num)
        this.frequency++
        this.num=num
      }

    }
  })
</script>

</body>
</html>